package com.wyg.state;

/**
 * @description:
 * @author: WYG
 * @time: 2021/4/7 9:31
 */

public class SoldState implements State{
    GumballMachine gumballMachine;
    public SoldState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }
    @Override
    public void insertQuarter() {
        System.out.println("稍等，正在为您出糖果");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("抱歉，您已经转动曲柄，要出糖果了");
    }

    @Override
    public void turnCrank() {
        System.out.println("不能两次转动曲柄");
    }

    @Override
    public void dispense() {
        gumballMachine.releaseBall();
        if (gumballMachine.getCount() > 0) {
            gumballMachine.setState(gumballMachine.getNoQuarterState());
        } else {
            System.out.println("没有糖果了");
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }
    }
}
